package com.mfl.controller.admin;

import com.mfl.common.PageResult;
import com.mfl.common.Result;
import com.mfl.pojo.dto.KYCourseVideoDTO;
import com.mfl.pojo.dto.KYCourseVideoPageQueryDTO;
import com.mfl.pojo.vo.KYCourseVideoVO;
import com.mfl.service.KYCourseVideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/cky/admin/courseVideo")
public class KYCourseVideoController {

    @Autowired
    private KYCourseVideoService kyCourseVideoService;

    /**
     * 添加课程视频
     * @param kyCourseVideoDTO
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody KYCourseVideoDTO kyCourseVideoDTO){
        log.info("添加课程视频：{}", kyCourseVideoDTO);
        kyCourseVideoService.insert(kyCourseVideoDTO);
        return Result.success("添加成功");
    }

    /**
     * 分页查询课程视频
     * @param kyCourseVideoPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(KYCourseVideoPageQueryDTO kyCourseVideoPageQueryDTO){
        log.info("分页查询课程视频：{}", kyCourseVideoPageQueryDTO);
        PageResult pageResult = kyCourseVideoService.page(kyCourseVideoPageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 根据id查询课程视频
     * @return
     */
    @GetMapping("/getCourseVideoById")
    public Result<KYCourseVideoVO> getCourseVideoById(int id){
        log.info("根据id查询课程视频：{}", id);
        KYCourseVideoVO kyCourseVideoVO = kyCourseVideoService.getCourseVideoById(id);
        return Result.success("", kyCourseVideoVO);
    }

    /**
     * 修改课程视频
     * @param kyCourseVideoDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody KYCourseVideoDTO kyCourseVideoDTO){
        log.info("修改课程视频：{}", kyCourseVideoDTO);
        kyCourseVideoService.update(kyCourseVideoDTO);
        return Result.success("修改成功");
    }

    /**
     * 批量删除课程视频
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestParam List<Integer> ids){
        log.info("批量删除课程视频：{}", ids);
        kyCourseVideoService.batchDelete(ids);
        return Result.success("删除成功");
    }
}
